/**
 * 测试接口
 */
import { post, get } from "@/utils/axios";
// import axios from "axios";post,
// import { message } from "antd";
const timeout = 1000000;

export async function testGet(area) {
  const url = `/api-juhe/simpleWeather/query`;
  const params = {
    city: area,
    key: "a955e4bef62b5d3a70fc852ada4dab5c"
  };
  try {
    const res = await get(url, params);
    if (res && res.error_code === 0) {
      return { type: true, res }; //正常数据
    } else {
      return { type: false, msg: "" };
    }
  } catch (error) {
    console.log("error==test=api==", error);
    return { type: false, msg: "" };
  }
}

//聚合数据-字典免费接口
export async function dictGet(word) {
  const url = `/api-word/xhzd/query`;
  const params = {
    word,
    key: "5bf8684d7ff3fbac5430d91101a7f1c6"
  };
  try {
    const res = await post(url, params);
    if (res && res.error_code === 0) {
      return { type: true, res }; //正常数据
    } else {
      return { type: false, msg: "" };
    }
  } catch (error) {
    console.log("error==test=api==", error);
    return { type: false, msg: "" };
  }
}

//ip地址及真实地址获取
export async function addressGet(ip = "") {
  const url = `/api-juhe/ip/ipNew`;
  const params = {
    ip,
    key: "87c7dfa20ee1083b3cb18032ba21a16f"
  };
  try {
    const res = await get(url, params, { timeout: timeout });
    if (res && res.error_code === 0) {
      return { type: true, res: res };
    } else {
      return { type: false, msg: "请求失败" };
    }
  } catch (error) {
    console.log("error==test=api==", error);
    return { type: false, msg: "请求失败" };
  }
}

//获取在线图片
export async function getImages(width, height, num) {
  // 创建一个axios 实例
  // const axiosInstance = axios.create({
  //   timeout: 60000,
  //   responseType: 'json',
  //   headers: {
  //     'Content-Type': 'application/json;charset=utf-8',
  //   },
  // });
  const url = `/api-bing/HPImageArchive.aspx?format=js&idx=${1}&n=1&mkt=en-US`;
  // const params = { random: num };
  try {
    const res = await get(url, null, { timeout: timeout });
    console.log("res===", res);
  } catch (error) {
    // console.log("test==error==", error)
    // return require('@/assets/img/10355.jpg')
  }
}

/**
 * @name getNewsList
 * @description 获取热点新闻-模拟瀑布流
 */
export async function getNewsList(type) {
  const url = `/api-word/toutiao/index`;
  try {
    const params = {
      type,
      key: "89efece56bd977421eb5500462638bfc"
    };
    const res = await get(url, params, { OPENLOADIN: "UNUSE" });
    if (res && res.error_code === 0) {
      return { type: true, data: res.result.data };
    } else {
      return { type: false, msg: "请求失败" };
    }
  } catch (error) {
    console.log(error);
    return { type: false, msg: "请求失败" };
  }
}
